package com.avicsafety.ezsystem;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.avicsafety.ezsystem.android_networking.NetworkingActivity;
import com.avicsafety.ezsystem.butter_knife.ButterKnifeActivity;

import com.avicsafety.ezsystem.local_stoage.LocalStorageActivity;
import com.avicsafety.ezsystem.mvp.MvpTestActivity;
import com.avicsafety.ezsystem.pdf.PdfActivity;
import com.avicsafety.ezsystem.rxjava.RxJavaActivity;


public class MainActivity extends AppCompatActivity {

    private Button btn_rxjava;
    private Button btn_networking;
    private Button btn_pdf;
    private Button btn_butter_knife;
    private Button btn_databinding;
    private Button btn_crash;
    private Button btn_localstorage;
    private Button btn_mvp;


    private Context othis;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        othis = this;

        btn_rxjava=findViewById(R.id.btn_rxjava);
        btn_rxjava.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
           startActivity(new Intent(othis, RxJavaActivity.class));
            }
        });

        btn_networking=findViewById(R.id.btn_networking);
        btn_networking.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
           startActivity(new Intent(othis, NetworkingActivity.class));
            }
        });


        btn_pdf=findViewById(R.id.btn_pdf);
        btn_pdf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
           startActivity(new Intent(othis, PdfActivity.class));
            }
        });


        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat
                    .requestPermissions(
                            this,
                            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                            1);
        }

        btn_butter_knife=findViewById(R.id.btn_butter_knife);
        btn_butter_knife.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(othis, ButterKnifeActivity.class));
            }
        });


        btn_crash=findViewById(R.id.btn_crash);
        btn_crash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                try{
//                    String s = "";
//                    System.out.println(s.charAt(1));
//                }catch (Exception e){
//                    //AlertDialog dialog = new AlertDialog(othis);
//                }
                String s = "";
                System.out.println(s.charAt(1));
            }
        });

        btn_localstorage=findViewById(R.id.btn_localstorage);
        btn_localstorage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(othis, LocalStorageActivity.class));
            }
        });

        btn_mvp=findViewById(R.id.btn_mvp);
        btn_mvp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(othis, MvpTestActivity.class));
            }
        });


    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case 1: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                } else {
                    finish();
                }
                return;
            }
        }
    }
}
